﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace Model
{
    /// <summary>
    /// 启动配置
    /// </summary>
    public class StartConfig : Entity
    {
        public int AppId { get; set; }
        public AppType AppType { get; set; }

        /// <summary>
        /// Http监听的端口
        /// </summary>
        public string ServerIP { get; set; }
        public bool IsRun { get; set; }
        public string OuterIP { get; set; }
        public string InnerIP { get; set; }

        /// <summary>
        /// 获取外网监听端口
        /// </summary>
        /// <returns></returns>
        public IPEndPoint GetOuterIP()
        {
            if (!string.IsNullOrWhiteSpace(this.OuterIP))
            {
                string[] temp = this.OuterIP.Split(":");
                return new IPEndPoint(temp[0] == "*" ? IPAddress.Any : IPAddress.Parse(temp[0]), int.Parse(temp[1]));
            }
            return null;
        }

        /// <summary>
        /// 获取内网监听端口
        /// </summary>
        /// <returns></returns>
        public IPEndPoint GetInnerIP()
        {
            if (!string.IsNullOrWhiteSpace(this.InnerIP))
            {
                string[] temp = this.InnerIP.Split(":");
                return new IPEndPoint(temp[0] == "*" ? IPAddress.Any : IPAddress.Parse(temp[0]), int.Parse(temp[1]));
            }
            return null;
        }

        /// <summary>
        /// 获取Http监听的端口
        /// </summary>
        /// <returns></returns>
        public string GetServerIP()
        {
            return $"http://{this.ServerIP}";
        }
    }
}
